import { ref } from "vue"
/**
 * @description 分页
 * */
export const usePagination = (callback: () => void) => {
  interface Page {
    pageSizes: number[]
    pageIndex: number
    pageSize: number
    totalSize: number
  }
  const page = ref<Page>({
    pageSizes: [10, 20, 50, 100],
    pageIndex: 1,
    pageSize: 10,
    totalSize: 0
  })
  /** 分页 显示数量改变 */
  const handleSizeChange = (val: number) => {
    page.value.pageIndex = 1
    page.value.pageSize = val
    callback()
  }
  /** 分页 当前页数改变 */
  const handleCurrentChange = (val: number) => {
    page.value.pageIndex = val
    callback()
  }
  return { page, handleSizeChange, handleCurrentChange }
}
